package edu.jd.homeworkstudent;

import edu.jd.common.Utils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class HomeworkStuService {

    public List<HomeworkStuDto> getHomework(String stu_id){
        SqlSession sess = Utils.openSession();
        try{
            HomeworkStuDao dao = sess.getMapper(HomeworkStuDao.class);
            List<HomeworkStuDto> homework = dao.getStuHomework(stu_id);
            sess.commit();
            return homework;
        }catch (Exception e){
            e.printStackTrace();
            sess.rollback();
            throw new RuntimeException("获取作业失败");
        }finally {
            sess.close();
        }
    }

    public void submitHomework(Integer hk_id, String stu_id, String hk_submit){
        SqlSession sess = Utils.openSession();
        try{
            HomeworkStuDao dao = sess.getMapper(HomeworkStuDao.class);
            dao.updateHomework(hk_id, stu_id, hk_submit);
            sess.commit();
        }catch (Exception e){
            e.printStackTrace();
            sess.rollback();
            throw new RuntimeException("提交作业失败");
        }finally {
            sess.close();
        }
    }

}
